#
# Sample simulation
#
from OOSwarm.simulation import Simulation
from OOSwarm.boid import Boid
from OOSwarm.mindset import BasicFlockingMindset
import PyCarrara
from PyCarrara import *
from random import uniform
from OOSwarm.Container import BoxContainer
from OOControls.sceneParser import SceneParser,Controller,Parameter,PARM_ON_OFF,PARM_ABSOLUTE_DISTANCE,SimulationControl,BoidControl,Controls
FPS = 24.0
CONTROLLERS = [Controller(name="Simulation",parm_list=[Parameter(name="Running",typ=PARM_ON_OFF)]),
               Controller(name="Boid",parm_list=[
                  Parameter(attribute="min_speed",typ=PARM_ABSOLUTE_DISTANCE,name="Min speed per second"),
                  Parameter(attribute="max_speed",typ=PARM_ABSOLUTE_DISTANCE,name="Max speed per second"),
                  Parameter(attribute="velocity",typ=PARM_ABSOLUTE_DISTANCE,name="Initial speed per second"),
                  Parameter(attribute="max_acceleration",typ=PARM_ABSOLUTE_DISTANCE,name="Max acceleration per second per second"),
                  ])] 




class SampleSimulation(Simulation):
  def init(self):
    self.scene.fps = FPS
    sp = SceneParser()
    sp.build_tree()
    self.control_list = Controls(sp.get_controllers(cont_list=CONTROLLERS))
    sim = self.control_list.get_first(control_class=SimulationControl)

    (self.start_time,self.end_time) = sim.get_boundaries()
#     self.scene.add_camera(name="Conical",focus_name="CameraFocus")
    self.add_boids()
#     self.scene.container = BoxContainer(position=Vector(-100.0,-100.0,0.0),size=Vector(200.0,200.0,100.0))
    
  def add_boids(self):   
    for c in self.control_list.get_subset(control_class=BoidControl) :
       b = Boid(obj=c.carrara_object.object,
                  mindset=BasicFlockingMindset(self.scene,sociable=uniform(0.0,1.0),prudent=uniform(0.0,1.0)),max_turn=360.0 ,
                  min_speed=c.get_parameter_value(c.get_parameter("min_speed"),self.start_time),
                  max_speed=c.get_parameter_value(c.get_parameter("max_speed"),self.start_time))
       b.refresh()
       c.carrara_object = b
#       self.scene.add_boid(b)
#       b.refresh()
#       b.velocity = Vector(0.0,-5.0,0.0)
          
    print "Done"   
    
    
SampleSimulation()